let 與 const 與 Arrow Function


Posted by cmtilo on 2021-05-03

宣告變數的新選擇:let 與 const

用法就跟var一樣,letconstant的生存範圍只在{ }。
const是指constant,是常數,不會變。
盡量用let,因為寫程式時,作用域範圍越小越好,不會去影響到其他也容易debug。

箭頭函式 Arrow Function

const test = (n) => { return n }

例如

var arr = [1,2,3,4,5]
arr
 .filter(funcion(value){
  return value >1
 })
 .map(function(value){
  return value *2
 })

可簡化成

arr
 .filter(value => value>1)
 .map(value=> value *2)

#let #const #arrowfunction







Related Posts

簡明約耳趣談軟體(Joel on Software)導讀書摘

簡明約耳趣談軟體(Joel on Software)導讀書摘

5. 頻譜分析

5. 頻譜分析

用後端好朋友們 express & sequelize 實作部落格

用後端好朋友們 express & sequelize 實作部落格


Comments